﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Asteroids
{
    class Asteroid : GameObject
    {
        public bool small { get; set; }                 //Small asteroid?
        private SpriteBatch spriteBatch;
        private Texture2D sprite;

        public Asteroid(Game g, Vector2 position_in, Vector2 velocity_in, bool small_in, float speed_increase)
            : base(g)
        {
            Position = position_in;
            Velocity = velocity_in * speed_increase;
            Rotation = 0;
            small = small_in;
            collided();
        }

        protected override void LoadContent()
        {
            Random random = new Random();
            int randInt = random.Next(1, 5);
            sprite = Game.Content.Load<Texture2D>("Asteroid-Asteroid" + randInt.ToString() + "N");
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);
        }

        public override void Draw(GameTime gameTime)
        {
            float scale = 1.0f;
            if (small)
                scale = 0.5f;

            Vector2 offset =
             new Vector2(sprite.Width / 2 * scale,
                         sprite.Height / 2 * scale);

            wrapAround(800, 500, sprite.Width/1.5f * scale, sprite.Height/1.5f * scale);     //Wraps around if obj goes off-screen

            boundingRectangle = new Rectangle((int)Position.X - (int)offset.X,      //Updates obj's boundingRectangle
                                              (int)Position.Y - (int)offset.Y,
                                              (int)(sprite.Width * scale),
                                              (int)(sprite.Height * scale));
            spriteBatch.Begin();
            spriteBatch.Draw(sprite,
                             Position,
                             null,
                             Color.White,
                             Rotation,
                             offset,
                             scale,
                             SpriteEffects.None,
                             0);
            spriteBatch.End();
        }

        public override void Update(GameTime gameTime)
        {
            float elapsedSeconds = (float) gameTime.ElapsedGameTime.TotalSeconds;
            Position += Velocity * elapsedSeconds;
        } 
    }
}